package com.aspose.cells.b.a.g;

import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
import java.nio.charset.CoderResult;
import java.nio.charset.CodingErrorAction;

public class zc {
   private Charset b;
   private CharsetEncoder c = null;

   public zc(Charset var1) {
      this.b = var1;
      this.c = this.b.newEncoder().onMalformedInput(CodingErrorAction.REPLACE).onUnmappableCharacter(CodingErrorAction.REPLACE);
   }

   public int a(char[] var1, int var2, int var3, byte[] var4, int var5, boolean var6) throws Exception {
      if (var1 == null) {
         throw new NullPointerException("chars");
      } else if (var4 == null) {
         throw new NullPointerException("bytes");
      } else if (var3 >= 0 && var2 >= 0 && var2 + var3 <= var1.length) {
         if (var5 >= 0 && var5 <= var4.length) {
            assert (float)var3 * this.c.maxBytesPerChar() <= (float)(var4.length - var5);

            CharBuffer var7 = CharBuffer.wrap(var1, var2, var3);
            int var8 = var4.length - var5;
            ByteBuffer var9 = ByteBuffer.wrap(var4, var5, var8);
            CoderResult var10 = this.c.encode(var7, var9, false);
            if (var10.isOverflow()) {
               this.c.encode(var7, var9, true);
               var10 = this.c.flush(var9);
            }

            if (var10.isOverflow()) {
               throw new IllegalArgumentException("Encode Overflow: insufficient space in the 'bytes' array.");
            } else {
               int var11 = var8 - var9.remaining();
               return var11;
            }
         } else {
            throw new IndexOutOfBoundsException("byteIndex");
         }
      } else {
         throw new IndexOutOfBoundsException("charIndex, charCount");
      }
   }
}
